package meow.async

import meow.Timeline

/** フォロー（お気に入り）を外す非同期サービス  */
class UnFollowService {

  boolean transactional = true
  static expose = ['jms']
  static destination = "queue.unfollow"

  def onMessage = {follower ->
    log.info "----async unfollow ${follower.owner.username}:${follower.target.username}"
    try {
      // HQLでサブクエリ付きbulk deleteはこんな風にするらしい(where句にサブクエリを書く)
      Timeline.executeUpdate("""
delete Timeline t
where t.ownername = ?
  and t.statusOwner = (select a from Account a where a.username = ?)
      """, [follower.owner.username, follower.target.username])
    }
    catch (e) { e.printStackTrace() }
    log.info "====ASYNC UNFOLLOW"
  }
}
